package com.lvmama.pangolin.controller;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import com.lvmama.pangolin.conf.WebSecurityConfig;
import com.lvmama.pangolin.entity.City_Model;
import com.lvmama.pangolin.entity.mt.MTTicketProduct;
import com.lvmama.pangolin.mt.service.MTTicketCommodityItemsService;
import com.lvmama.pangolin.mt.service.MTTicketProductService;
import com.lvmama.pangolin.util.ProductRelationshipHotelUtil;
import com.lvmama.pangolin.util.ProductRelationshipUtil;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import com.lvmama.pangolin.entity.ProductConditionVO;
import com.lvmama.pangolin.entity.RelevanceProduct;
import com.lvmama.pangolin.entity.hotel.HotelProductDetail;
import com.lvmama.pangolin.entity.link.TicketCommodityLink;
import com.lvmama.pangolin.entity.lmm.LMMTicketProduct;
import com.lvmama.pangolin.entity.qnr.QNRTicketCommodityItem;
import com.lvmama.pangolin.entity.qnr.QNRTicketProduct;
import com.lvmama.pangolin.entity.tc.TCTicketProduct;
import com.lvmama.pangolin.entity.tn.TNTicketProduct;
import com.lvmama.pangolin.entity.xc.XCTicketProduct;
import com.lvmama.pangolin.hotel.service.HotelCommodityDetailService;
import com.lvmama.pangolin.hotel.service.HotelProductDetailService;
import com.lvmama.pangolin.lmm.service.LMMTicketProductService;
import com.lvmama.pangolin.qnr.service.QNRTicketCommodityItemsService;
import com.lvmama.pangolin.qnr.service.QNRTicketProductService;
import com.lvmama.pangolin.service.CityService;
import com.lvmama.pangolin.service.RelevanceCommodityService;
import com.lvmama.pangolin.service.RelevanceProductService;
import com.lvmama.pangolin.tc.service.TCCommodityItemsService;
import com.lvmama.pangolin.tc.service.TCTicketProductService;
import com.lvmama.pangolin.tn.service.TNTicketCommodityItemsService;
import com.lvmama.pangolin.tn.service.TNTicketProductService;
import com.lvmama.pangolin.xc.service.XCTicketCommodityItemsService;
import com.lvmama.pangolin.xc.service.XCTicketProductService;

/**
 * 产品关联业务逻辑
 */
@Controller
@RequestMapping("/datashow")
public class MatchController {
	private static final Logger logger = Logger.getLogger(MatchController.class);
	@Autowired
	private LMMTicketProductService lProductService;
	@Autowired
	private XCTicketProductService xcProductService;
	@Autowired
	private TNTicketProductService tnProductService;
	@Autowired
	private TCTicketProductService tcProductService;
	@Autowired
	private QNRTicketProductService qnrProductService;

	//新增美团
	@Autowired
	private MTTicketProductService mtProductService;
	@Autowired
	private CityService cityService;
	@Autowired
	private RelevanceProductService relevanceProductService;//表：product_rel
	@Autowired
	private RelevanceCommodityService relevanceCommodityService;
	@Autowired
	private TCCommodityItemsService tcCommodityService;
	@Autowired
	private XCTicketCommodityItemsService xcCommodityService;
	@Autowired
	private TNTicketCommodityItemsService tnCommodityService;
	@Autowired
	private QNRTicketCommodityItemsService qnrCommodityService;

	@Autowired
	private MTTicketCommodityItemsService mtCommodityService;
	@Autowired
	private HotelProductDetailService hotelProductService;//表：hotel_pdetail
	@Autowired
	private HotelCommodityDetailService hotelCommodityService;
	@Autowired
	private ProductRelationshipUtil productRelationshipUtil;
	@Autowired
	private ProductRelationshipHotelUtil productRelationshipHotelUtil;


	/***
	 * 展示产品的关联关系：从product_rel表中查询出关联关系展示到主界面
	 * @param model
	 * @param pc
	 * @param request
	 * @return
	 */
	@RequestMapping("/list")
	public String productList(ModelMap model,ProductConditionVO pc,HttpServletRequest request){
		List<RelevanceProduct> relevances=new ArrayList<RelevanceProduct>();//产品关联关系表：product_rel
		String businessCode=pc.getBusinessCode();
		if(businessCode==null||"".equals(businessCode)||"TICKET".equals(businessCode)){
			List<LMMTicketProduct> listPro =lProductService.getAllList(pc);//查询驴妈妈所有门票产品
			
			for (int i=0;i<listPro.size();i++){
	        	LMMTicketProduct product=listPro.get(i);
				City_Model city = cityService.queryCityById(product.getCityCode());
	        	product.setCityCode(city.getName());
	        	product.setProvince(city.getProvinceName());
	        	RelevanceProduct relevanceProduct=relevanceProductService.viewRelevance(product.getProductId(),businessCode);
	        	if(relevanceProduct!=null){
	        		relevances.add(relevanceProduct);//此处为门票，查询产品关系表：product_rel，作为主界面展示
	        	}else{
	        		product.setIsLink(1);//驴妈妈该产品不存在关联关系
	        	}
	        }
			PageInfo<LMMTicketProduct> page = new PageInfo<LMMTicketProduct>(listPro);
			model.addAttribute("page", page);
	        model.addAttribute("product", page.getList());
	        
	        
		}else if("HOTEL".equals(businessCode)){
			List<HotelProductDetail> hotelProducts=hotelProductService.findByProductVO(pc);
			for(HotelProductDetail product:hotelProducts){
				product.setCityCode(cityService.queryCityById(product.getCityCode()).getName());
				RelevanceProduct relevanceProduct=relevanceProductService.viewRelevance(product.getProductId(),businessCode);
				if(relevanceProduct!=null){
	        		relevances.add(relevanceProduct);//此处为酒店，查询产品关系表：product_rel，作为主界面展示与门票不同处在于表中business_code
	        	}else{
	        		product.setIsLink(1);//驴妈妈该产品不存在关联关系
	        	}
			}
			PageInfo<HotelProductDetail>page=new PageInfo<HotelProductDetail>(hotelProducts);
			model.addAttribute("page", page);
	        model.addAttribute("product", page.getList());
		}
		model.addAttribute("relevances", relevances);
		model.addAttribute("productConditionVO", pc);
        model.addAttribute("businessCode",businessCode);

		return "datashow/list";
	}


	/**
	 * 从具体的产品表中查询产品信息
	 * 选择要进行关联的产品,选择关联的产品分两类,其中
	 * 门票：在对应公司编码的ticket_product_xx(xx代表公司编码)下查询
	 * 酒店：在表：hotel_pdetail下根据公司编码，景区名称查询
	 * @param companyCode
	 * @param sceneryName
	 * @param selectSceneryName
	 * @param businessCode
	 * @return
	 */
	@RequestMapping("/select")
	@ResponseBody
	public Object select(String companyCode,String sceneryName,String selectSceneryName,String businessCode,String province,String starLevel,String lvProductId,String cityCode){
		Map<String, Object> result = getResult();
		LMMTicketProduct lmmTicketProduct = lProductService.selectByProductId(lvProductId);
		if(lmmTicketProduct!=null)
		{
			lmmTicketProduct.setProvince(province);
			lmmTicketProduct.setCityCode(cityCode);
			if(lmmTicketProduct.getStarLevel()==null||"".equals(lmmTicketProduct.getStarLevel()))
			{
				lmmTicketProduct.setStarLevel(starLevel);
			}
		}
		if(businessCode==null||"".equals(businessCode)||"TICKET".equals(businessCode)){//根据公司编码查询对应公司的产品数据库
			if ("xc".equals(companyCode)){
				List<XCTicketProduct> xcProduct=null;
				if(selectSceneryName!=null && !"".equals(selectSceneryName))
				{
					xcProduct=xcProductService.selectByName(selectSceneryName);
				}else{
					xcProduct=xcProductService.selectAll();
				}

				if(xcProduct!=null&&xcProduct.size()>0){//此处没有查询过省份，故省份没有进行过评分
					productRelationshipUtil.matchAndSortXCProduct(lmmTicketProduct,xcProduct);
					//对得到的竞品进行遍历，如果已经关联，则到关联表中查询lmm对应的product_id，再通过这个product_id到lmm的产品表中查询lmm的产品名称
					for(XCTicketProduct xcp:xcProduct){
						if(xcp.getIs_link()==1){
							List<String> lmmName=relevanceProductService.findNameByRelProdId(businessCode,companyCode,xcp.getProductId());
							System.out.println(lmmName.size());

							if(lmmName!=null&&lmmName.size()>0){
								xcp.setSceneryName(xcp.getSceneryName()+"_"+lmmName.get(0));
							}
						}
					}
					result.put("product", xcProduct);
				}else{
					result.put("msg", "没有可匹配的产品！");
				}
				
			}else if("tn".equals(companyCode)){
				List<TNTicketProduct> tnProduct=null;
				if(selectSceneryName!=null && !"".equals(selectSceneryName))
				{
					tnProduct=tnProductService.selectByName(selectSceneryName);
				}else{
					tnProduct=tnProductService.selectAll();
				}

				if(tnProduct!=null&&tnProduct.size()>0){
					productRelationshipUtil.matchAndSortTNProduct(lmmTicketProduct,tnProduct);
					//对得到的竞品进行遍历，如果已经关联，则到关联表中查询lmm对应的product_id，再通过这个product_id到lmm的产品表中查询lmm的产品名称
					for(TNTicketProduct tnp:tnProduct){
						if(tnp.getIs_link()==1){
							List<String> lmmName=relevanceProductService.findNameByRelProdId(businessCode,companyCode,tnp.getProductId());
							if(lmmName!=null&&lmmName.size()>0){
								tnp.setSceneryName(tnp.getSceneryName()+"_"+lmmName.get(0));
							}
						}
					}
					result.put("product", tnProduct);
				}else{
					result.put("msg", "没有可匹配的产品！");
				}
				
			}else if("tc".equals(companyCode)){
				List<TCTicketProduct> tcProduct= null;
				if(selectSceneryName!=null && !"".equals(selectSceneryName))
				{
					tcProduct=tcProductService.selectByName(selectSceneryName);
				}else
				{
					tcProduct=tcProductService.selectAll();
				}
				if(tcProduct!=null&&tcProduct.size()>0){
					productRelationshipUtil.matchAndSortTCProduct(lmmTicketProduct,tcProduct);
					//对得到的竞品进行遍历，如果已经关联，则到关联表中查询lmm对应的product_id，再通过这个product_id到lmm的产品表中查询lmm的产品名称
					for(TCTicketProduct tcp:tcProduct){
						if(tcp.getIs_link()==1){
							List<String> lmmName=relevanceProductService.findNameByRelProdId(businessCode,companyCode,tcp.getProductId());
							if(lmmName!=null&&lmmName.size()>0){
								tcp.setSceneryName(tcp.getSceneryName()+"_"+lmmName.get(0));
							}
						}
					}
					result.put("product", tcProduct);
				}else{
					result.put("msg", "没有可匹配的产品！");
				}
				
			}else if("qnr".equals(companyCode)){
				List<QNRTicketProduct> qnrProduct= null;
				if(selectSceneryName!=null && !"".equals(selectSceneryName))
				{
					qnrProduct = qnrProductService.selectByName(selectSceneryName);
				}else
				{
					qnrProduct = qnrProductService.selectAll();
				}

				if(qnrProduct!=null&&qnrProduct.size()>0){

					productRelationshipUtil.matchAndSortQNRProduct(lmmTicketProduct,qnrProduct);
					//对得到的竞品进行遍历，如果已经关联，则到关联表中查询lmm对应的product_id，再通过这个product_id到lmm的产品表中查询lmm的产品名称
					for(QNRTicketProduct qnrp:qnrProduct){
						if(qnrp.getIs_link()==1){
							List<String> lmmName=relevanceProductService.findNameByRelProdId(businessCode,companyCode,qnrp.getProductId());
							if(lmmName!=null&&lmmName.size()>0){
								qnrp.setSceneryName(qnrp.getSceneryName()+"_"+lmmName.get(0));
							}
						}
					}
					result.put("product", qnrProduct);
				}else{
					result.put("msg", "没有可匹配的产品！");
				}
			}
			//新增美团
			else if("mt".equals(companyCode)){
				List<MTTicketProduct> mtProduct = null;
				if(selectSceneryName!=null && !"".equals(selectSceneryName))
				{
					mtProduct = mtProductService.selectByName(selectSceneryName);//根据景点名称查找
				}else
				{
					mtProduct = mtProductService.selectAll();
				}

				if(mtProduct!=null&&mtProduct.size()>0){
					productRelationshipUtil.matchAndSortMTProduct(lmmTicketProduct,mtProduct);
					//对得到的竞品进行遍历，如果已经关联，则到关联表中查询lmm对应的product_id，再通过这个product_id到lmm的产品表中查询lmm的产品名称
					for(MTTicketProduct mtp:mtProduct){
						if(mtp.getIs_link()==1){
							List<String> lmmName=relevanceProductService.findNameByRelProdId(businessCode,companyCode,mtp.getProductId());
							if(lmmName!=null&&lmmName.size()>0){
								mtp.setSceneryName(mtp.getSceneryName()+"_"+lmmName.get(0));
							}
						}
					}
					result.put("product", mtProduct);
				}else{
					result.put("msg", "没有可匹配的产品！");
				}
			}
		}else if("HOTEL".equals(businessCode)){
			/**
			 * 优化此处，使得检索酒店产品时能够得到与驴妈妈酒店最为匹配的酒店
			 */
			HotelProductDetail lmmHotel = new HotelProductDetail();
			if(selectSceneryName!=null && !"".equals(selectSceneryName))
			{
				lmmHotel.setHotelName(selectSceneryName);
			}else
			{
				lmmHotel.setHotelName(sceneryName);
			}
			if(cityCode!=null && !"".equals(cityCode))
			{
				lmmHotel.setCityCode(cityCode);
			}
			List<HotelProductDetail> hotels=hotelProductService.findByString(companyCode.toUpperCase()+"_C_CODE",selectSceneryName);
			if(hotels!=null&&hotels.size()>0){
//				后期产品表中加上is_link字段后再讲这段代码解开
				Collections.sort(hotels,new Comparator<HotelProductDetail>() {
					@Override
					public int compare(HotelProductDetail o1, HotelProductDetail o2) {
						if(o1.getIsLink()>o2.getIsLink()){
							return 1;
						}else if(o1.getIsLink()==o2.getIsLink()){
							return 0;
						}else{
							return -1;
						}
						
					}
				});
				//对得到的竞品进行遍历，如果已经关联，则到关联表中查询lmm对应的product_id，再通过这个product_id到lmm的产品表中查询lmm的产品名称
				for(HotelProductDetail hotel:hotels){
					if(hotel.getIsLink()==1){
						List<String> lmmName=relevanceProductService.findNameByRelProdId(businessCode,companyCode,hotel.getProductId());
						if(lmmName!=null&&lmmName.size()>0){
							hotel.setHotelName(hotel.getHotelName()+"_"+lmmName.get(0));
						}
					}
				}
				productRelationshipHotelUtil.sortHotelProduct(hotels,lmmHotel);//根据酒店名称和城市对酒店列表进行排序
				result.put("hotels", hotels);
			}else{
				result.put("msg", "没有可匹配的产品！");
			}
		}
		return result;
	}
	/**
	 * 进行关联：关联时会根据业务编号操作product_rel,和产品表，对于门票类：ticket_product_xx
	 * @param product
	 * @param prodIdOther
	 * @param prodNameOther
	 * @param
	 * @return
	 */
	@RequestMapping("/link")
	@ResponseBody
	public Object link(RelevanceProduct product,String prodIdOther,String prodNameOther){
		
		String companyCode=product.getCompanyCode();
		String productId=product.getProdId();
		String businessCode=product.getBusinessCode();
		/**
		 * 1.对产品关联表进行插入活更新操作
		 * 2.将产品表所在的isLink字段改为1
		 */
		//1.对产品关联表进行插入活更新操作表：product_rel表，改表包含门票和酒店的业务为管理关联关系的表，business_code字段区分酒店和门票

		if ("xc".equals(companyCode)){
			product.setProdIdXC(prodIdOther);
			product.setProdNameXC(prodNameOther);
			if(relevanceProductService.viewRelevance(productId,businessCode)!=null){
				relevanceProductService.updateXC(product);
			}else{
				relevanceProductService.insertXC(product);
			}	
			
		}else if("tn".equals(companyCode)){
			product.setProdIdTN(prodIdOther);
			product.setProdNameTN(prodNameOther);
			if(relevanceProductService.viewRelevance(productId,businessCode)!=null){
				relevanceProductService.updateTN(product);
			}else{
				relevanceProductService.insertTN(product);
			}
			
		}else if("tc".equals(companyCode)){
			product.setProdIdTC(prodIdOther);
			product.setProdNameTC(prodNameOther);
			if(relevanceProductService.viewRelevance(productId,businessCode)!=null){
				relevanceProductService.updateTC(product);
			}else{
				relevanceProductService.insertTC(product);
			}

			
		}else if("qnr".equals(companyCode)){
			product.setProdIdQNR(prodIdOther);
			product.setProdNameQNR(prodNameOther);
			if(relevanceProductService.viewRelevance(productId,businessCode)!=null){
				
				relevanceProductService.updateQNR(product);
			}else{
				relevanceProductService.insertQNR(product);
			}
		}else if("el".equals(companyCode)){
			product.setProdIdEL(prodIdOther);
			product.setProdNameEL(prodNameOther);
			if(relevanceProductService.viewRelevance(productId,businessCode)!=null){
				
				relevanceProductService.updateEL(product);
			}else{
				relevanceProductService.insertEL(product);
			}
		}
		//新增美团对产品进行关联操作
		else if("mt".equals(companyCode)){
			product.setProdIdMT(prodIdOther);
			product.setProdNameMT(prodNameOther);
			if(relevanceProductService.viewRelevance(productId,businessCode)!=null){

				relevanceProductService.updateMT(product);
			}else{
				relevanceProductService.insertMT(product);
			}
		}

		//2.将产品表所在的isLink字段改为1，产品表为：ticket_product_xx:例如ticket_product_mt
		if(businessCode==null||"".equals(businessCode)||"TICKET".equals(businessCode)){
			if ("xc".equals(companyCode)){
				xcProductService.updateByProdId(prodIdOther);
				
			}else if("tn".equals(companyCode)){
				tnProductService.updateByProdId(prodIdOther);
				
			}else if("tc".equals(companyCode)){
				tcProductService.updateByProdId(prodIdOther);

				
			}else if("qnr".equals(companyCode)){
				qnrProductService.updateByProdId(prodIdOther);
			}else if("mt".equals(companyCode)){//新增美团逻辑
				mtProductService.updateByProdId(prodIdOther);
			}
		}else if("HOTEL".equals(businessCode)){
			companyCode=companyCode.toUpperCase()+"_C_CODE";
			hotelProductService.setIsLinkd(companyCode, prodIdOther);//将酒店表：hotel_product_detail 字段is_

		}
		Map<String, Object> result = getResult();
		result.put("successMsg", "关联成功！");
		return result;
	}
	
	@RequestMapping("/deleteLink")
	@ResponseBody
	public Object deleteLink(RelevanceProduct product,String prodIdOther,String prodNameOther){
		String companyCode=product.getCompanyCode();
		String businessCode=product.getBusinessCode();
		/**
		 * 1.将关联表中的关联字段设置为空:关联表为：product_rel
		 * 2.将产品表中的is_link字段设为0:产品表为：门票类 - 例如：ticket_product_xx
		 * 3.将此产品对应的商品关联全部删除
		 * 4.将此商品表中的is_link改为0:商品表为：门票类 - 例如：ticket_pdetail_qnr
		 */
		if("xc".equals(companyCode)){
			product.setProdIdXC(prodIdOther);
			product.setProdNameXC(prodNameOther);
			//1.将关联表中的关联字段设置为空
			relevanceProductService.deleteXC(product);
			
			if("TICKET".equals(product.getBusinessCode())){
				//2.将产品表中的is_link字段设为0
				xcProductService.deleteLinkByProdId(prodIdOther);
				//4.将此商品表中的is_link改为0
				xcCommodityService.deleteLinkByProdCommId(prodIdOther, null);
			}else if("HOTEL".equals(product.getBusinessCode())){
				hotelProductService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther);
				hotelCommodityService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther,"");
			}	
			
		}else if("tn".equals(companyCode)){
			product.setProdIdTN(prodIdOther);
			product.setProdNameTN(prodNameOther);
			relevanceProductService.deleteTN(product);
			if("TICKET".equals(product.getBusinessCode())){
				tnProductService.deleteLinkByProdId(prodIdOther);
				tnCommodityService.deleteLinkByProdCommId(prodIdOther, null);
			}else if("HOTEL".equals(product.getBusinessCode())){
				hotelProductService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther);
				hotelCommodityService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther,"");
			}
			
		}else if("tc".equals(companyCode)){
			product.setProdIdTC(prodIdOther);
			product.setProdNameTC(prodNameOther);
			relevanceProductService.deleteTC(product);
			if("TICKET".equals(product.getBusinessCode())){
				tcProductService.deleteLinkByProdId(prodIdOther);
				tcCommodityService.deleteLinkByProdCommId(prodIdOther, null);
			}else if("HOTEL".equals(product.getBusinessCode())){
				hotelProductService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther);
				hotelCommodityService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther,"");
			}
			
		}else if("qnr".equals(companyCode)){
			product.setProdIdQNR(prodIdOther);
			product.setProdNameQNR(prodNameOther);
			relevanceProductService.deleteQNR(product);
			if("TICKET".equals(product.getBusinessCode())){
				qnrProductService.deleteLinkByProdId(prodIdOther);
				qnrCommodityService.deleteLinkByProdCommId(prodIdOther, null);
			}else if("HOTEL".equals(product.getBusinessCode())){
				hotelProductService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther);
				hotelCommodityService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther,"");
			}
			
		}else if("el".equals(companyCode)){//el 没有门票判断吗？
			product.setProdIdEL(prodIdOther);
			product.setProdNameEL(prodNameOther);
			relevanceProductService.deleteEL(product);
			if("HOTEL".equals(product.getBusinessCode())){
				hotelProductService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther);
				hotelCommodityService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther,"");
			}
		}else if("mt".equals(companyCode)){
			product.setProdIdMT(prodIdOther);
			product.setProdNameMT(prodNameOther);
			relevanceProductService.deleteMT(product);
			if("TICKET".equals(product.getBusinessCode())){
				mtProductService.deleteLinkByProdId(prodIdOther);
				mtCommodityService.deleteLinkByProdCommId(prodIdOther, null);
			}else if("HOTEL".equals(product.getBusinessCode())){
				hotelProductService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther);
				hotelCommodityService.deleteLinkd(companyCode.toUpperCase()+"_C_CODE", prodIdOther,"");
			}
		}
		/**
		 * //3.将此产品对应的商品关联全部删除
		 */
		TicketCommodityLink commLink=getCommLink();
		commLink.setProd_id(product.getProdId());
		commLink.setCompany_code(companyCode);
		commLink.setRel_prod_id(prodIdOther);
		commLink.setBusiness_code(businessCode);
		relevanceCommodityService.deleteCommodityLink(commLink);
		return null;
	}
	
    public Map<String, Object> getResult() {
        Map<String, Object> result = new HashMap<String, Object>();
        return result;
    }
    public TicketCommodityLink getCommLink(){
    	TicketCommodityLink commLink=new TicketCommodityLink();
    	return commLink;
    }
    @RequestMapping("/change/relevance/status")
	@ResponseBody
	public Map<String,String> changeRelevanceStatus(String relevanceId,String status){
    	Map<String,String> result = new HashMap<>();
    	try {
    		RelevanceProduct item = new RelevanceProduct();
        	item.setId(Integer.parseInt(relevanceId));
        	item.setIsDeal(Integer.parseInt(status));
        	relevanceProductService.updateRelevance(item);
        	result.put("Success","关联关系状态更新成功！");
		} catch (Exception e) {
			result.put("errorMessage","关联关系状态更新失败！");
			logger.error("更新产品关联关系状态异常："+e.getMessage()+",入参为：relevanceId="+relevanceId+",status="+status);
		}

		return result;
    }
}
